import { Router } from 'vue-router'
import { setRouteEmitter } from './guard/router-listener'
import setupPermissionGuard from './guard/permission'
import setupUserLoginGuard from './guard/userLoginInfo'

function setupPageGuard(router: Router) {
  router.beforeEach((to, from) => setRouteEmitter(to, from))
}

export const createRouterGuard = (router: Router) => {
  setupPageGuard(router)
  setupUserLoginGuard(router)
  setupPermissionGuard(router)
}

export const baseRouter = [
  {
    path: '/',
    name: 'home',
    component: () => import('@/layout/default-layout.vue'),
    children: [
      {
        path: '/login',
        name: 'login',
        component: () => import('@/views/login/index.vue'),
      },
      {
        path: '/userOrder',
        name: '用户订单',
        component: () => import('@/views/order/userOrder.vue'),
      },
      {
        path: '/registrationPhone',
        name: '登记照-教务',
        component: () => import('@/views/registration/registrationPhone.vue'),
      },
      {
        path: '/examinationTime',
        name: '教考',
        component: () => import('@/views/registration/examinationTime.vue'),
      },
      {
        path: '/electronicHelp',
        name: '帮助文档',
        component: () => import('@/views/electronic/electronicHelp.vue'),
      },
      {
        path: '/electronicSnapshot',
        name: '电子学会',
        component: () => import('@/views/electronic/electronicSnapshot.vue'),
      },
      // {
      //   path: '/home',
      //   name: '首页',
      //   redirect: '/home/index',
      //   component: () => import('@/layout/page-layout.vue'),
      //   children: [
      //     {
      //       name: 'home_index',
      //       path: '/home/index',
      //       component: () => import('@/views/home/index.vue'),
      //       meta: {
      //         isHidden: true,
      //       },
      //     },
      //     {
      //       name: ':id',
      //       path: ':id',
      //       component: () => import('@/views/home/index.vue'),
      //       meta: {
      //         isHidden: true,
      //       },
      //     },
      //   ],
      // },
      {
        path: '/error/:code',
        name: 'error',
        component: () => import('@/views/error/index.vue'),
      },
      {
        path: '/:pathMatch(.*)*',
        name: 'notFound',
        redirect: '/error/404',
      },
    ],
  },
]
